package dao

import (
	"gitee.com/cyanbleeze/go-image-management/internal/model"
	"gitee.com/cyanbleeze/go-image-management/pkg/app"
)

func (d *Dao) CreateFavorite(name string, desc string, uID uint) error {
	favorite := model.Favorite{
		Name:   name,
		Desc:   desc,
		UserID: uID,
	}
	return favorite.Create(d.engine)
}

func (d *Dao) UpdateFavorite(id uint, name string, desc string) error {
	favorite := model.Favorite{
		Name: name,
		Desc: desc,
	}
	favorite.ID = id
	return favorite.Update(d.engine)
}

func (d *Dao) DeleteFavorite(id uint) error {
	favorite := model.Favorite{}
	favorite.ID = id
	return favorite.Delete(d.engine)
}

func (d *Dao) GetFavorite(id uint, uID uint) (*model.Favorite, error) {
	favorite := model.Favorite{
		UserID: uID,
	}
	favorite.ID = id
	return favorite.Get(d.engine)
}

func (d *Dao) GetFavoriteList(uID uint, page int, pageSize int) ([]*model.Favorite, error) {
	favorite := model.Favorite{
		UserID: uID,
	}
	return favorite.List(d.engine, app.GetPageOffset(page, pageSize), pageSize)
}

func (d *Dao) CountFavoriteListByUID(uID uint) (int, error) {
	favorite := model.Favorite{
		UserID: uID,
	}
	return favorite.Count(d.engine)
}
